package com.leetcode.algorithm.y22.m08.w5;

/**
 * 
 * 376. 摆动序列
 * 
 * https://leetcode.cn/problems/wiggle-subsequence/
 * 
 * @author jie.deng
 *
 */
class Question0376Solution03 {

	public int wiggleMaxLength(int[] nums) {
		int len = nums.length;
		if (len <= 1) {
			return len;
		}
		int up = 1;
		int down = 1;
		for (int i = 1; i < len; i++) {
			if (nums[i] - nums[i - 1] > 0) {
				up = down + 1;
			} else if (nums[i] - nums[i - 1] < 0) {
				down = up + 1;
			}
		}

		return Math.max(up, down);
	}

}